define(function (require, exports, module) {
    require('./css/style.css')

    function onload() {
        return {
            template: require('./Widget.html'),
            props: {
                // 选项数组
                show: {
                    type: Boolean,
                    default: true,
                    required: false,
                },
                // 选项数组
                tabs: {
                    type: Array,
                    default: () => {
                        return []
                    },
                    required: false,
                },
                // 左内边距
                paddLeft: {
                    type: String,
                    default: '30px',
                    required: false,
                },
                // 右侧按钮数组
                rightBtns: {
                    type: Array,
                    default: () => {
                        return []
                    },
                    required: false
                }
            },
            data() {
                return {
                    cursor: 0
                };
            },
            mounted() {

            },
            methods: {
                // 切换选中状态
                toggleCheck(index) {
                    this.cursor = Number(index)
                    this.sliceTop(this.cursor)
                },
                // 根据当前选中项滑动内容
                sliceTop(index) {
                    let tab = this.$refs['sheetList']
                    let tabList = tab.children
                    tab.scrollTop = tabList[index].offsetTop - (index * 20)
                },
                // 监听滚动，并根据滚动距离切换选中状态
                listenScroll(e) {
                    let tab = this.$refs['sheetList']
                    let tabList = tab.children
                    for(let i = 0,len = tabList.length; i < len; i++) {
                        let curTop = tabList[i].offsetTop - (i * 20)
                        if (e.target.scrollTop > curTop - 20 && e.target.scrollTop < curTop + 20) {
                            this.cursor = i
                        }
                    }
                },
                // 右侧按钮触发点击事件
                triggerClick(eventName) {
                    this.$emit(eventName, {})
                }
            }
        }
    }

    module.exports = {
        onload
    };
});
